package com.sebiotec.ambassador.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;

import com.allen.library.base.BaseHttpUtil;
import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.sebiotec.ambassador.model.post.PostPwd;
import com.sebiotec.ambassador.net.BookApiHelper;
import com.sebiotec.ambassador.ui.view.LoadingDialog;
import com.sebiotec.basecommon.utils.constant.SjmConstant;
import com.sebiotec.basecommon.utils.language.LocalManageUtil;
import com.sebiotec.basecommon.utils.tools.ActivityTool;
import com.sebiotec.basecommon.utils.tools.SPUtils;


import java.util.HashMap;

import okhttp3.ResponseBody;

public class UpdatePwdViewModel extends AndroidViewModel {
    public UpdatePwdViewModel(@NonNull Application application) {
        super(application);
    }

    public MyUpdatePwdDataCallBack mDataCallBack;

    //数据回调接口
    public interface MyUpdatePwdDataCallBack<T> {
        void onDataSuccessCallBack(T t);
        void onDataFailCallBack(T t);
    }

    public  void  save(PostPwd bean, BasicViewModel.MyBasicDataCallBack<Object> mDataCallBack){
        LoadingDialog loadingDialog = new LoadingDialog(ActivityTool.getInstance().getLastActivity());
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(SjmConstant.LOGINID,""));
        map.put("Token", SPUtils.get(SjmConstant.TOKEN,""));
        map.put("Lang", LocalManageUtil.getSMJSetLanguageLocales(ActivityTool.getInstance().getLastActivity()));
        BookApiHelper.geRadomApi()
                .EditPwd(map,SPUtils.get(SjmConstant.LOGINID,""),new BaseHttpUtil<PostPwd>().convertVo2Json(bean))
                .compose(Transformer.<ResponseBody>switchSchedulers(loadingDialog))
                .subscribe(new CommonObserver<ResponseBody>() {
                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(errorMsg);
                    }

                    @Override
                    protected void onSuccess(ResponseBody s) {

                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });
    }


}
